package com.lanyou.esb.repository;

import java.util.List;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;

import com.lanyou.esb.entity.DefinedBundle;

public interface DefinedBundleRepository extends Repository<DefinedBundle, String>, JpaSpecificationExecutor<DefinedBundle> {

	@RestResource(exported = false)
	DefinedBundle  findByBundleCode(@Param("bundleCode") String bundleCode);
	
	@RestResource(exported = false)
	DefinedBundle  findByBundleName(@Param("bundleName") String bundleName);
	
	@RestResource(exported = false)
	DefinedBundle findById(@Param("id") String id);
	
	long count();

	boolean exists(String id);

	@RestResource(exported = true)
	@RequiresPermissions(value={"businessServiceManagement:maintain"})
	<S extends DefinedBundle> S save(S entity); // could expose REST API

	<S extends DefinedBundle> List<S> save(Iterable<S> entities);

	@RestResource(exported = true)
	@RequiresPermissions(value={"businessServiceManagement:view", "businessServiceManagement:maintain"}, logical = Logical.OR)
	DefinedBundle findOne(String id); // could expose REST API

	DefinedBundle getOne(String id);

	// 以下三个接口只能选一个暴露为REST API

	@RestResource(exported = false)
	List<DefinedBundle> findAll(); // could expose REST API

	@RestResource(exported = false)
	List<DefinedBundle> findAll(Sort sort); // could expose REST API

	@RestResource(exported = true)
	@RequiresPermissions(value={"businessServiceManagement:view", "businessServiceManagement:maintain"}, logical = Logical.OR)
	Page<DefinedBundle> findAll(Pageable pageable); // could expose REST API

	List<DefinedBundle> findAll(Iterable<String> ids);

	// 以下两个接口，要么都暴露为REST API，要么都不暴露
	@RestResource(exported = true)
	@RequiresPermissions(value={"businessServiceManagement:maintain"})
	void delete(String id); // could expose REST API

	@RestResource(exported = true)
	@RequiresPermissions(value={"businessServiceManagement:maintain"})
	void delete(DefinedBundle entity); // could expose REST API

	void delete(Iterable<? extends DefinedBundle> entities);

	void deleteAll();

	void flush();

	<S extends DefinedBundle> S saveAndFlush(S entity);

	void deleteInBatch(Iterable<DefinedBundle> entities);

	void deleteAllInBatch();

}